package com.kds.smarthome.common;

import lombok.Data;

import java.util.Map;

@Data
public class AjaxResponse<T> {
    private int code;
    private String message;
    private T data;

    private AjaxResponse(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> AjaxResponse<T> success(T data) {
        return new AjaxResponse<>(0, "操作成功", data);
    }

    public static <T> AjaxResponse<T> success(String message, T data) {
        return new AjaxResponse<>(0, message, data);
    }

    public static <T> AjaxResponse<T> error(int code, String message) {
        return new AjaxResponse<>(code, message, null);
    }

    public static <T> AjaxResponse<T> error(String message) {
        return new AjaxResponse<>(1, message, null);
    }

    public static AjaxResponse<Map<String, Object>> warning(String s, Map<String, Object> result) {
        return new AjaxResponse<>(1, s, result);
    }
}
